/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.dotexe.webframework.core.datasources;

import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;

import org.json.JSONException;

import com.dotexe.webframework.core.bindings.BindingSource;
import com.dotexe.webframework.core.eventargs.DataUpdate;
import com.dotexe.webframework.core.eventargs.RefreshStateArgs;

/**
 *
 * @author jovan.tomasevic
 */
public abstract class DataSource {
    private String name;
    protected Object Source;
    public BindingSource BindingSource;

    public DataSource(){

    }
    public DataSource(String name){
        this.name = name;
    }

    public Object getSource(){
        return this.Source;
    }

    public void setSource(Object value){
        this.Source = value;
    }

    public abstract void bind(java.util.ArrayList<String> propertiesTiBind)
            throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException, JSONException, NoSuchMethodException, InvocationTargetException, ParseException;

    public abstract void bind()
         throws ClassNotFoundException,NoSuchFieldException, IllegalAccessException, JSONException, NoSuchMethodException, InvocationTargetException, ParseException;


    public abstract void update(RefreshStateArgs args, DataUpdate updateParams)
            throws ClassNotFoundException,
            NoSuchFieldException,
            IllegalAccessException,
            JSONException,
            NoSuchMethodException,
            IllegalArgumentException,
            InvocationTargetException,
            ParseException;

    public String createPropertyName(String str){
        String propertyName = new String();
        propertyName = propertyName + str.charAt(0);
        propertyName = propertyName.toUpperCase();
        propertyName = propertyName + str.substring(1,str.length());
        return propertyName;
    }
    public String createGetMethodName(String attrName){
        return String.format("get%s", this.createPropertyName(attrName));
    }
    public String createSetMethodName(String attrName){
        return String.format("set%s", this.createPropertyName(attrName));
    }
    /**
     * @return the Name
     */
    public String getName() {
        return name;
    }

    /**
     * @param Name the Name to set
     */
    public void setName(String name) {
        this.name = name;
    }
}
